<template>
  <div class="app-container">
    <div class="filter-container">
      <span style="float:left;width:30%;">
        <el-input @keyup.enter.native="handleFilter" v-model="listQuery.tableName" placeholder="请输入表名" class="filter-item" />
      </span>
      <span style="float:left;margin-left: 10px;">
        <el-button @click="handleFilter" class="filter-item" type="primary" v-waves icon="el-icon-search">查询</el-button>
        <el-button @click="generateCode" :disabled="btnDisabled" class="filter-item" type="warning" v-waves icon="el-icon-download">生成代码</el-button>
      </span>
    </div>
    <!-- 表格 -->
    <el-table :data="list" @selection-change="selectChange" v-loading="listLoading" border fit highlight-current-row style="width: 100%;height: 100%;">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column width="60px" align="center" label="序号">
        <template slot-scope="scope">
          <span>{{ scope.$index +1 + (listQuery.limit*(listQuery.page-1))}}</span>
        </template>
      </el-table-column>

      <el-table-column show-overflow-tooltip prop="tableName" label="表名" align="center" />
      <el-table-column prop="tableComment" label="表备注" align="center" />
      <el-table-column prop="createTime" label="创建时间" align="center" />
    </el-table>
    
    <!-- 分页 -->
    <div v-show="!listLoading" class="pagination-container">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>

    <!-- 添加修改弹出框页面组件 -->
    <setting v-if="showAdd" @flushList="flushList" @closeDialog="closeDialog" 
      :showAdd="showAdd" :multipleSelection="multipleSelection" />

  </div>
</template>

<script>
  /* mixins */
  import pageListMixin from '@/mixins/pageList/pageListMixin.js'
  
  /* 组件 */
  import Setting from './setting.vue'
  
  import * as common from '@/utils/base/common'

  export default {
    /*  内容: 代码生成器-mybatisplus  */
    name: 'codeGeneratorPlus',
    data() {
      return {
        restPath: 'generatorplus/table',
        listQuery: {
          page: 1,
          limit: 10,
          tableName: '',
        },
        multipleSelection: [],
      }
    },
    mixins: [pageListMixin],
    components: {
      Setting
    },
    methods: {
      initData() {
        this.getList()
      },
      
      selectChange(val){
        this.multipleSelection = val;
      },
      
      // 生成代码
      generateCode(){
        if(this.multipleSelection.length > 0) {
          this.showAdd = true;
        } else {
          common.message(this, 'warning', 2, '请至少选中一行')
        }
      }

    } // methods end
  }
</script>
<style scoped>
  @import "~@/styles/list.css";
</style>